package chatmodels;
import interfaces.ChatModel;

import java.util.Observer;
import java.util.Scanner;

import event.ObservableEvent;


public class TestingModel implements ChatModel{
	
	private String message = new String();
	private ObservableEvent messageReceived = new ObservableEvent();
	


	@Override
	public void addInputReceivedListener(Observer observer){
		this.messageReceived.addObserver(observer);

	}


	@Override
	public void sendMessage(String message) {

		this.message = message;
	}

	@Override
	public String getMessage() {
		String message = this.message;
		this.message = "";
		return message;
	}
	@Override
	public void waitForMessages(){
		new Thread(new Runnable() {
			public void run() {
				Scanner scanner = new Scanner(System.in);
				while (true) {
						if(!message.equals("")){
							messageReceived.notifyEvent();
						}
					
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

	
	
}
